//IvV
let sunny_option1x     = 0;
let sunny_option1y     = 0;
let sunny_option1angle = 0;
let sunny_option2x     = 0;
let sunny_option2y     = 0;
let sunny_option2angle = 0;
let sunny_option3x     = 0;
let sunny_option3y     = 0;
let sunny_option3angle = 0;
let sunny_option4x     = 0;
let sunny_option4y     = 0;
let sunny_option4angle = 0;

/**
 * Tj[pCjVCY
 */
function Initialize_Sunny(){
	HiSpeed = 4.5;
	LowSpeed = 2.5;
	Intersection = 0;
	Graze = 50;
	Rebirth = 12;
	RebirthReduction = 2;
	InitialBomb = 3;
	ItemCollect = 160;
	
	GaugeRecovery = 3.6;
	GaugeShieldUse = 4.5;
	ShieldRadius = 58;
	ChargePlus = 2;
	
	imgPlayer = imgPlayer_Sunny;
	
	//vC[摜[h
	LoadGraphic( imgPlayer );
	
	//摜[h
	LoadGraphic( imgSpread );
	
	//vC[ݒꊇŃZbg
	SetPlayerSettings();
	
	//ő`[WJEgݒ
	SetMaxChargeCount( 5 );
	
	//IvVݒ
	sunny_option1angle =   0;
	sunny_option2angle =  90;
	sunny_option3angle = 180;
	sunny_option4angle = 270;
}

/**
 * Tj[pC[v
 */
function MainLoop_Sunny(){
	let optionrot = 3.5;
	
	sunny_option1angle += optionrot;
	sunny_option2angle += optionrot;
	sunny_option3angle += optionrot;
	sunny_option4angle += optionrot;
	
	sunny_option1x = GetPlayerX() + sin( sunny_option1angle ) * 6;
	sunny_option1y = GetPlayerY() - 34 + cos( sunny_option1angle ) * 5;
	sunny_option2x = GetPlayerX() + sin( sunny_option2angle ) * 6;
	sunny_option2y = GetPlayerY() - 34 + cos( sunny_option2angle ) * 5;
	sunny_option3x = GetPlayerX() + sin( sunny_option3angle ) * 6;
	sunny_option3y = GetPlayerY() - 34 + cos( sunny_option3angle ) * 5;
	sunny_option4x = GetPlayerX() + sin( sunny_option4angle ) * 6;
	sunny_option4y = GetPlayerY() - 34 + cos( sunny_option4angle ) * 5;
}

/**
 * Tj[p`揈
 */
function DrawLoop_Sunny(){
	//IvVS̕`
	SetTexture( imgPlayer );
	SetGraphicRect( 0, 42, 20, 60 );
	SetGraphicScale( 1, 1 );
	DrawGraphic( sunny_option1x, sunny_option1y );
	DrawGraphic( sunny_option2x, sunny_option2y );
	DrawGraphic( sunny_option3x, sunny_option3y );
	DrawGraphic( sunny_option4x, sunny_option4y );
}

/**
 * Tj[pt@CiCY
 */
function Finalize_Sunny(){
}

/**
 * Tj[pVbg
 * 
 * @param {Integer} count VbgpJE^
 */
function Shot_Sunny( count ){
	let angle1 = 0;
	let angle2 = 0;
	let angle3 = 0;
	let angle4 = 0;
	let pow = 0;
	let way = 5;
	let sspan = 8;
	let aspan = 0;
	
	//Cgp[eBN
	if( count % sspan == 0 ){
		if( Key_SlowMove == KEY_FREE || Key_SlowMove == KEY_PULL ){
			//ړ
			aspan = 3;
			pow = 2.6;
		}else{
			//ᑬړ
			aspan = 5;
			pow = 2.6;
		}
		
		ascent( i in 0..way ){
			CreateObjPlayerShot( GetPlayerX(), GetPlayerY(), 10, 270 + ( ( -way + 1 ) / 2 + i ) * aspan, pow, 1, US_BALL_F_ORANGE, 64 );
		}
	}
	
	//Tj[[U[
	if( Key_SlowMove == KEY_FREE || Key_SlowMove == KEY_PULL ){
		//ړ
		angle1 = GetGapAngle( GetPlayerX(), GetPlayerY(), sunny_option1x, sunny_option1y );
		angle2 = GetGapAngle( GetPlayerX(), GetPlayerY(), sunny_option2x, sunny_option2y );
		angle3 = GetGapAngle( GetPlayerX(), GetPlayerY(), sunny_option3x, sunny_option3y );
		angle4 = GetGapAngle( GetPlayerX(), GetPlayerY(), sunny_option4x, sunny_option4y );
		pow = 0.8;
	}else{
		//ᑬړ
		angle1 = 270;
		angle2 = 270;
		angle3 = 270;
		angle4 = 270;
		pow = 0.6;
	}
	
	SunnyLaser( sunny_option1x, sunny_option1y, angle1, pow );
	SunnyLaser( sunny_option2x, sunny_option2y, angle2, pow );
	SunnyLaser( sunny_option3x, sunny_option3y, angle3, pow );
	SunnyLaser( sunny_option4x, sunny_option4y, angle4, pow );
}

/**
 * Tj[p`[WVbg
 */
task ChargeShot_Sunny(){
	let px = GetPlayerX();
	let py = GetPlayerY();
	let xy = GetFrontEnemyXY( px, py, 60 );
	let ey = py - 200;
	
	if( xy[0] != NULL ){
		ey = xy[1];
	}
	
	ChargeBullet1_Sunny( px, py, px, ey,  1, 14 );
	ChargeBullet1_Sunny( px, py, px, ey, -1, 14 );
	
	FWait( 14 );
	
	SpreadEffect_Sunny( px, ey, 60 );
	loop( 60 ){
		ChargeBullet2_Sunny( px, ey );
		yield;
	}
}

/**
 * Tj[p`[WVbge1
 */
task ChargeBullet1_Sunny( x, y, tox, toy, roll, time ){
	let angle = GetGapAngle( x, y, tox, toy ) + time * roll;
	let dist = GetGapLength( x, y, tox, toy );
	let speed = dist / time;
	let count = 0;
	
	let obj = CreateObjSinuateLaser( x, y, speed, angle, 10, 10, 186, 0 );
	ObjShot_SetDamage( obj, 5 );
	ObjShot_SetPenetration( obj, 1000 );
	Obj_SetAlpha( obj, 128 );
	
	while( !Obj_BeDeleted( obj ) ){
		angle -= roll * 1.8;
		Obj_SetAngle( obj, angle );
		x = Obj_GetX( obj );
		y = Obj_GetY( obj );
		DeleteEnemyShotImmediatelyInCircle( SHOT, x, y, 64 );
		count += 1;
		if( count > time ){
			Obj_Delete( obj );
		}
		yield;
	}
}

/**
 * Tj[p`[WVbge2
 */
task ChargeBullet2_Sunny( x, y ){
	let obj = CreateObjShot( x, y, 0, 0, 49, 0 );
	Obj_SetAlpha( obj, 0 );
	ObjShot_SetDamage( obj, 11 );
	DeleteEnemyShotImmediatelyInCircle( SHOT, x, y, 64 );
	
	yield;
	
	if( !Obj_BeDeleted( obj ) ){
		Obj_Delete( obj );
	}
}

/**
 * Tj[[U[
 */
task SunnyLaser( x, y, angle, pow ){
	let obj = CreateObjLaser( x, y, 0, angle, 800, 60, 186, 0, false );
	Obj_SetAlpha( obj, 32 );
	ObjEffect_SetLayer( obj, 2 );
	ObjShot_SetDamage( obj, pow );
	
	yield;
	
	if( !Obj_BeDeleted( obj ) ){
		Obj_Delete( obj );
	}
}

/**
 * Tj[p`[WVbgo
 */
task SpreadEffect_Sunny( x, y, count ){
	let obj = Obj_Create( OBJ_EFFECT );
	let alpha = 255;
	let maxcount = count;
	let gcount = 0;
	ObjEffect_SetTexture( obj, imgSpread );
	ObjEffect_SetPrimitiveType( obj, PRIMITIVE_TRIANGLESTRIP );
	ObjEffect_CreateVertex( obj, 4 );
	ObjEffect_SetVertexXY( obj, 0, -310, -100 );
	ObjEffect_SetVertexXY( obj, 1, -310,  100 );
	ObjEffect_SetVertexXY( obj, 2,  310, -100 );
	ObjEffect_SetVertexXY( obj, 3,  310,  100 );
	ObjEffect_SetLayer( obj, 3 );
	ObjEffect_SetRenderState( obj, ADD );
	Obj_SetPosition( obj, x, y );
	
	while( count > 0 ){
		if( (count > maxcount - 17) || (count < 17) ){
			gcount += 1;
		}
		
		ObjEffect_SetVertexUV( obj, 0,         310 * trunc( gcount / 17 )  ,         100 * ( gcount % 17 )   );
		ObjEffect_SetVertexUV( obj, 1,         310 * trunc( gcount / 17 )  , 100 + ( 100 * ( gcount % 17 ) ) );
		ObjEffect_SetVertexUV( obj, 2, 310 + ( 310 * trunc( gcount / 17 ) ),         100 * ( gcount % 17 )   );
		ObjEffect_SetVertexUV( obj, 3, 310 + ( 310 * trunc( gcount / 17 ) ), 100 + ( 100 * ( gcount % 17 ) ) );
		if( count < 18 ){
			alpha -= 17;
			ascent( i in 0..4 ){
				ObjEffect_SetVertexColor( obj, i, alpha, 255, 255, 255 );
			}
		}
		count -= 1;
		yield;
	}
	if( !Obj_BeDeleted( obj ) ){
		Obj_Delete( obj );
	}
}